/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Entity.FileTA;
import Entity.User;
import Model.FileTAModel;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileUploadException;

/**
 *
 * @author mr2
 */
public class SidangTAController extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, FileUploadException {
        String page = request.getParameter("page");
        RequestDispatcher dis = null;
        
        if(page != null){
            
            /*
             * Controller fungsi kelola Sidang TA
             * 
             * */
            if(page.equals("statusTA")){
                PendaftaranSidangTALogic statusTA = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(statusTA.StatusTAMahasiswa());
                dis.forward(request, response);
            } 
            //Menampilkan form data sidang
            else if(page.equals("formDataTA")){
                PendaftaranSidangTALogic dataTA = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(dataTA.formDataTA());
                dis.forward(request, response);
            }
            //Menginputkan data sidang
            else if(page.equals("inputDataSidang")){
                PendaftaranSidangTALogic dataSidang = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(dataSidang.inputDataTA());
                dis.forward(request, response);
            }
            //Menampilkan form daftar sidang
            else if(page.equals("formDaftarSidang")){
                PendaftaranSidangTALogic formSidang = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(formSidang.FormDaftarSidang());
                dis.forward(request, response);
            }
            //Melakukan proses pendaftaran sidang proposal
            else if(page.equals("daftarProposal")){
                PendaftaranSidangTALogic proposal = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(proposal.daftarProposal());               
                dis.forward(request, response);     
            }  
            //Melakukan proses pendaftaran sidang progress
//            else if(page.equals("daftarProgress")){
//                PendaftaranSidangTALogic proposal = new PendaftaranSidangTALogic(request);
//                dis = request.getRequestDispatcher(proposal.daftarProgress());
//                dis.forward(request, response);     
//            }       
            //Melakukan proses pendaftaran sidang final
            else if(page.equals("daftarFinal")){
                PendaftaranSidangTALogic proposal = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(proposal.daftarFinal());
                dis.forward(request, response);     
            }            
            //Menampilkan list pendaftar sidang pada akun koorTA
            else if(page.equals("listPendaftarSidang")){
                PendaftaranSidangTALogic listPendaftar = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(listPendaftar.ListPendaftarSidang());
                dis.forward(request, response);
            }            
            //Menampilkan detail pendaftar sidang pada akun koorTA
            else if(page.equals("detailPendaftarSidang")){
                PendaftaranSidangTALogic detailPendaftar = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(detailPendaftar.KoorTADetailPendaftarSidang());
                dis.forward(request, response);
            }
            //Melakukan update dan persetujuan sidang pada akun koorTA
            else if(page.equals("updateDataSidang")){
                PendaftaranSidangTALogic updateDaftarSidang = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(updateDaftarSidang.UpdateDataPendaftarSidang());
                dis.forward(request, response);
            }
            
            //Melakukan update dan persetujuan sidang pada akun koorTA
            else if(page.equals("persetujuanSidang")){
                PendaftaranSidangTALogic setujuSidang = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(setujuSidang.persetujuanPendaftarSidang());
                dis.forward(request, response);
            }
            
            //Menampilkan rekap pendaftar final untuk membuat form revisi dan berita acara bagi TU bagian akademik
            else if(page.equals("rekapPendaftarFinal")){
                PendaftaranSidangTALogic jadwalSidang = new PendaftaranSidangTALogic(request);
                dis = request.getRequestDispatcher(jadwalSidang.rekapPendaftarFinal());
                dis.forward(request, response);
            }
            
            /*
             * Controller fungsi Jadwal sidang
             * 
             * */
            
            //Mengarahkan pada halaman list Jadwal Sidang pada akun petugas lab
            else if(page.equals("listJadwalSidang")){
                JadwalSidangTALogic jadwalSidang = new JadwalSidangTALogic(request);
                dis = request.getRequestDispatcher(jadwalSidang.KelolaJadwalSidang());
                dis.forward(request, response);
            }
            else if(page.equals("jadwalSidang")){
                JadwalSidangTALogic jadwalSidang = new JadwalSidangTALogic(request);
                dis = request.getRequestDispatcher(jadwalSidang.JadwalSidang());
                dis.forward(request, response);
            }
            
            //Menampilkan form untuk menjadwalkan sidang tugas akhir
            else if(page.equals("detailJadwalSidang")){
                JadwalSidangTALogic jadwalSidang = new JadwalSidangTALogic(request);
                dis = request.getRequestDispatcher(jadwalSidang.DetailJadwalSidang());
                dis.forward(request, response);
            }
            
            //Menampilkan form untuk menjadwalkan sidang tugas akhir
            else if(page.equals("penjadwalanSidang")){
                JadwalSidangTALogic jadwalSidang = new JadwalSidangTALogic(request);
                dis = request.getRequestDispatcher(jadwalSidang.PenjadwalanSidang());
                dis.forward(request, response);
            }
            
            
            /*
             * Controller fungsi Berita acara TA
             * 
             * */
            
            //Menampilkan list berita Acata sidang TA
            else if(page.equals("listBeritaAcara")){
                BeritaAcaraTALogic beritaAcara = new BeritaAcaraTALogic(request);
                dis = request.getRequestDispatcher(beritaAcara.ListBeritaAcara());
                dis.forward(request, response);
            }
            
            //Menampilkan halaman detail berita acara
            else if(page.equals("detailBeritaAcara")){
                BeritaAcaraTALogic beritaAcara = new BeritaAcaraTALogic(request);
                dis = request.getRequestDispatcher(beritaAcara.DetailBeritaAcara());
                dis.forward(request, response);
            }
            
            //Melakukan perekaman berita acara
            else if(page.equals("rekamBeritaAcara")){
                BeritaAcaraTALogic beritaAcara = new BeritaAcaraTALogic(request);
                dis = request.getRequestDispatcher(beritaAcara.RekamBeritaAcara());
                dis.forward(request, response);
            }
            
            else if(page.equals("rekapBeritaAcara")){
                BeritaAcaraTALogic beritaAcara = new BeritaAcaraTALogic(request);
                dis = request.getRequestDispatcher(beritaAcara.RekapBeritaAcaraTA());
                dis.forward(request, response);
            }
            
            else if(page.equals("updateStatusTA")){
                BeritaAcaraTALogic statusTA = new BeritaAcaraTALogic(request);
                dis = request.getRequestDispatcher(statusTA.UpdateStatusTA());
                dis.forward(request, response);
            }
            else if(page.equals("detailRekapBeritaAcara")){
                BeritaAcaraTALogic beritaAcara = new BeritaAcaraTALogic(request);
                dis = request.getRequestDispatcher(beritaAcara.DetailRekapBeritaAcara());
                dis.forward(request, response);
            }
            
            /*
             * Controller fungsi Yudisium
             * 
             * */
            
            else if(page.equals("kelolaYudisium")){
                YudisiumLogic kelolaYudisium = new YudisiumLogic(request);
                dis = request.getRequestDispatcher(kelolaYudisium.KelolaYudisiumTA());
                dis.forward(request, response);
            }
            else if(page.equals("inputYudisium")){
                YudisiumLogic input = new YudisiumLogic(request);
                dis = request.getRequestDispatcher(input.inputYudisium());
                dis.forward(request, response);
            }
            else if(page.equals("detailYudisium")){
                YudisiumLogic detail = new YudisiumLogic(request);
                dis = request.getRequestDispatcher(detail.DetailYudisium());
                dis.forward(request, response);
            }
            else if(page.equals("updateYudisium")){
                YudisiumLogic update = new YudisiumLogic(request);
                dis = request.getRequestDispatcher(update.UpdateYudisium());
                dis.forward(request, response);
            }
            else if(page.equals("hapusYudisium")){
                YudisiumLogic update = new YudisiumLogic(request);
                dis = request.getRequestDispatcher(update.HapusYudisium());
                dis.forward(request, response);
            }
            
            /*
             * Controller fungsi Bimbingan TA
             * 
             * */
            
            if(page.equals("kelolaPembimbing")){
                BimbinganTALogic kelolaPembimbing = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(kelolaPembimbing.ListPembimbing());
                dis.forward(request, response);
            }
            else if(page.equals("setPembimbing1")){
                BimbinganTALogic kelolaPembimbing = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(kelolaPembimbing.setPembimbing1());
                dis.forward(request, response);
            }
            
            //Menampilkan list bimbingan TA mahasiswa
            else if(page.equals("listBimbinganTA")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.MhsListBimbingan());
                dis.forward(request, response);
            }
            
            else if(page.equals("formBimbinganTA")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.formBimbinganTA());               
                dis.forward(request, response);     
            }
            
            //Melakukan perekaman bimbingan TA
            else if(page.equals("rekamBimbinganTA")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.catatBimbinganTA());
                dis.forward(request, response);
            }
            
            else if(page.equals("mhsDetailBimbingan")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.MhsDetailBimbingan());
                dis.forward(request, response);
            }
            
            //Menampilkan list Mahasiswa bimbingan seorang dosen
            else if(page.equals("listMhsBimbingan")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.DosenListMhsBimbingan());
                dis.forward(request, response);
            }
            
            else if(page.equals("listBimbinganMhs")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.DosenListBimbinganMhs());
                dis.forward(request, response);
            }
            
            else if(page.equals("dosenDetailBimbingan")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.DosenDetailBimbinganMhs());
                dis.forward(request, response);
            }
            
            else if(page.equals("updateBimbinganTA")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.UpdateBimbingan());
                dis.forward(request, response);
            }
            
            else if(page.equals("dosenUpdateBimbinganTA")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.DosenUpdateBimbingan());
                dis.forward(request, response);
            }
            
            else if(page.equals("setujuBimbinganTA")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.SetujuBimbingan());
                dis.forward(request, response);
            }
            
            else if(page.equals("rekapBimbinganTA")){
                BimbinganTALogic bimbinganTA = new BimbinganTALogic(request);
                dis = request.getRequestDispatcher(bimbinganTA.RekapBimbinganTA());
                dis.forward(request, response);
            }
            
            /*
             * Controller fungsi kelola File TA
             * 
             * */
            
            //Menampilkan Status TA Mahasiswa
            else if(page.equals("kelolaFileTA")){
                FileTALogic file = new FileTALogic(request, response);
                dis = request.getRequestDispatcher(file.KelolaFileTA());
                dis.forward(request, response);
            }
            
            if(page.equals("listFileTA")){
                FileTALogic file = new FileTALogic(request, response);
                dis = request.getRequestDispatcher(file.ListFileTA());
                dis.forward(request, response);
            }
            //Menampilkan form daftar sidang
            else if(page.equals("uploadFileTA")){
                FileTALogic file = new FileTALogic(request, response);
                dis = request.getRequestDispatcher(file.UploadFileTA());
                dis.forward(request, response);

            }
            //Melakukan proses pendaftaran sidang proposal
            else if(page.equals("downloadFileTA")){
                FileTALogic file = new FileTALogic(request, response);
                dis = request.getRequestDispatcher(file.DownloadFileTA());               
                //dis.forward(request, response);                    
            }
            
            else if(page.equals("hapusFileTA")){
                FileTALogic file = new FileTALogic(request, response);
                dis = request.getRequestDispatcher(file.DeleteFileTA());               
                dis.forward(request, response);                    
            }
            
            /*
             * Controller fungsi kelola Berita TA
             * 
             * */
            
            else if(page.equals("kelolaBeritaTA")){
                BeritaTALogic beritaTA = new BeritaTALogic(request);
                dis = request.getRequestDispatcher(beritaTA.KelolaBeritaTA());
                dis.forward(request, response);
            }
            //Menampilkan detail berita
            else if(page.equals("detailBeritaTA")){
                BeritaTALogic beritaTA = new BeritaTALogic(request);
                dis = request.getRequestDispatcher(beritaTA.DetailBeritaTA());               
                dis.forward(request, response);     
            }
            //Melakukan proses pendaftaran sidang proposal
            else if(page.equals("formBeritaTA")){
                BeritaTALogic beritaTA = new BeritaTALogic(request);
                dis = request.getRequestDispatcher(beritaTA.formBeritaTA());               
                dis.forward(request, response);     
            }  
            //Melakukan proses pendaftaran sidang progress
            else if(page.equals("buatBeritaTA")){
                BeritaTALogic beritaTA = new BeritaTALogic(request);
                dis = request.getRequestDispatcher(beritaTA.BuatBeritaTA());
                dis.forward(request, response);     
            }       
            //Melakukan proses pendaftaran sidang final
            else if(page.equals("hapusBeritaTA")){
                BeritaTALogic beritaTA = new BeritaTALogic(request);
                dis = request.getRequestDispatcher(beritaTA.HapusBeritaTA());
                dis.forward(request, response);     
            }            
            //Menampilkan list pendaftar sidang pada akun koorTA
            else if(page.equals("listBeritaTA")){
                BeritaTALogic beritaTA = new BeritaTALogic(request);
                dis = request.getRequestDispatcher(beritaTA.ListBeritaTA());
                dis.forward(request, response);
            }            

            //Melakukan update dan persetujuan sidang pada akun koorTA
            else if(page.equals("beritaTAFull")){
                BeritaTALogic beritaTA = new BeritaTALogic(request);
                dis = request.getRequestDispatcher(beritaTA.BeritaTAFull());
                dis.forward(request, response);
            }
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException{
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(SidangTAController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException{
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(SidangTAController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
